home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 1 / Macwelt DVD 1.toast / Web-Publishing / HTML-Editoren / Alpha ƒ / Mode Examples / Stata-Example.do < prev    next >
Encoding:
Text File  |  2000-10-30  |  6.2 KB  |  251 lines

  1. /*
  2.  * ==========================================================================
  3.  * Stata-Example.do
  4.  * 
  5.  * Distributed as an example of Alpha's Stta mode.
  6.  * 
  7.  * Stata mode is available in the Statistical Modes package at
  8.  * 
  9.  * <ftp://ftp.ucsd.edu/pub/alpha/>
  10.  * ==========================================================================
  11.  */
  12.  
  13. /* 
  14.  * ==========================================================================
  15.  *  Corporate Policies Analysis - Exploring 30 years of family benefits
  16.  * 
  17.  *  FILE: "cps-1-1.do"
  18.  *                                    created: 10/11/99 {10:39:52 pm} 
  19.  *                                last update: 06/13/00 {03:51:33 pm} 
  20.  *  Description: 
  21.  *  
  22.  *  Adjusting weights according to instructions in appendix Q This involves
  23.  *  eliminating some observations from the 1963 through 1975 data sets. 
  24.  *  The output file will indicate how many observations were dropped.
  25.  *  
  26.  *  This creates and adds value labels for the variable "region" for data
  27.  *  sets mar65 through mar98.
  28.  *  
  29.  *  At the end of this procedure, all of the cps marXX.dta files will be
  30.  *  deleted.  Best to have them backed up on a disk somewhere!
  31.  *  
  32.  *  Author: Craig Barton Upright
  33.  *  E-mail: <cupright@princeton.edu>
  34.  *    mail: Princeton University, Department of Sociology
  35.  *          Princeton, New Jersey 08544
  36.  *     www: <http://www.princeton.edu/~cupright>
  37.  *  
  38.  *  Copyright (c) 1998-2000 Craig Barton Upright
  39.  * 
  40.  *  All rights reserved.
  41.  * ==========================================================================
  42.  */
  43.  
  44.  
  45. *** Preliminaries
  46.  
  47. #delimit ;
  48.  
  49. clear           ;
  50. set more 1      ;
  51. set memory 100m ;
  52. set matsize 50  ;
  53.  
  54.  
  55. *** Defining Macros ;
  56.  
  57. * Excerpt from Appendix Q:
  58. * It is important to note that the CPS files produced by the Census Bureau
  59. * do not have decimal points in the data.  It is left to the documentation
  60. * to inform the user how many decimals are implied.  The user must make the
  61. * proper adjustment before using weights.  This is true for all the
  62. * weights.  ;
  63.  
  64. * creating a little macro to recode, label, trim ;
  65.  
  66. program define macro1 ;
  67.  
  68.     /*  recoding weights */
  69.     
  70.     keep if wgt > 0 ;
  71.     replace wgt = wgt * .01 ;
  72.     
  73.     /*  creating region variable */
  74.     
  75.     generate region = _state ;
  76.     
  77.     recode region
  78.     
  79.         01 = 01
  80.         02 = 01
  81.         03 = 02
  82.         04 = 02
  83.         05 = 02
  84.         06 = 03
  85.         07 = 03
  86.         08 = 03
  87.         09 = 03
  88.         10 = 04
  89.         11 = 05
  90.         12 = 05
  91.         13 = 05
  92.         14 = 05
  93.         15 = 06
  94.         16 = 06
  95.         17 = 07
  96.         18 = 07
  97.         19 = 08
  98.         20 = 09
  99.         21 = 09 ;
  100.     
  101.     label define cdcodes
  102.     
  103.         01 "01 New England           "
  104.         02 "02 Middle Atlantic       "
  105.         03 "03 East North Central    "
  106.         04 "04 West North Central    "
  107.         05 "05 South Atlantic        "
  108.         06 "06 East South Central    "
  109.         07 "07 West South Central    "
  110.         08 "08 Mountain              "
  111.         09 "09 Pacific               " ;
  112.     
  113.     label values region cdcodes ;
  114.     
  115.     label variable region "Census Bureau Division" ;
  116.     
  117.     /* selecting variables */
  118.     
  119.     keep  year wgt region _child18 sex occ ind2d ;
  120.     
  121.     end ;
  122.  
  123.     
  124. * a second macro that calls "macro1" ;
  125.  
  126. program define macro2 ;
  127.  
  128.     clear ;
  129.  
  130.     ! echo "recoding state 19`1'"       ;
  131.     ! uncompress ../data-temp/mar`1'*       ;
  132.  
  133.     use ../data-temp/mar`1'.dta             ;
  134.     generate year = 19`1'                   ;
  135.     macro1                                  ;
  136.     quietly compress                        ;
  137.     codebook                                ;
  138.     save ../data-temp/cps`1'-1-1.dta        ;
  139.     clear                                   ;
  140.  
  141.     ! compress ../data-temp/mar`1'.dta      ;
  142.     ! compress ../data-temp/cps`1'-1-1.dta  ;
  143.     
  144.     end                                     ;
  145.     
  146.  
  147. *** Recoding ;
  148.  
  149. ! echo "recoding state for cps 65 - 69"  ;
  150.  
  151. macro2 65  ;
  152. macro2 66  ;
  153. macro2 67  ;
  154. macro2 68  ;
  155. macro2 69  ;
  156.  
  157. ! echo "cps weights assigned" ;
  158.  
  159.  
  160. * transforming variables in sppa-1-1.dta  ;
  161.  
  162. use ../data/sppa-1-1.dta  ;
  163.  
  164.  
  165. *** Encoding missing values ;
  166.  
  167. ! echo "encoding sppa missing values ..."  ;
  168.  
  169. mvdecode _all, mv(-9) ;
  170. mvdecode _all, mv(-8) ;
  171. mvdecode _all, mv(-7) ;
  172. mvdecode _all, mv(-1) ;
  173.  
  174.  
  175. *** Adding value labels ;
  176.  
  177. ! echo "adding sppa value labels ..." ;
  178.  
  179. label   define  yearlab 
  180.  
  181.     0      " 0 1982                                 "    
  182.     1      " 1 1992                                 "
  183.     2      " 2 1997                                 " ;
  184.  
  185. label   define  gender          
  186.  
  187.     9      "-9 NOT ASCERTAINED                      "
  188.     8      "-8 DON'T KNOW                           "
  189.     7      "-7 REFUSED                              "
  190.     2      "-2 INAPPLICABLE, SAMPLE SCREEN          "
  191.     1      "-1 INAPPLICABLE, QUESTION SCREEN        "
  192.     1      " 1 MALE                                 "
  193.     2      " 2 FEMALE                               " ;
  194.  
  195. label   define  racelab  
  196.  
  197.     9      "-9 NOT ASCERTAINED                      "
  198.     8      "-8 DON'T KNOW                           "
  199.     7      "-7 REFUSED                              "
  200.     2      "-2 INAPPLICABLE, SAMPLE SCREEN          "
  201.     1      "-1 INAPPLICABLE, QUESTION SCREEN        "
  202.     1      " 1 WHITE, BUT NOT OF HISPANIC ORIGIN    "
  203.     2      " 2 BLACK, BUT NOT OF HISPANIC ORIGIN    "
  204.     3      " 3 OTHER                                " ;
  205.  
  206.  
  207.  
  208. label   values  sppayear yearlab  ;
  209. label   values  sex  gender   ;
  210. label   values  race     racelab  ;
  211.  
  212.  
  213. *** Quick regression ;
  214.  
  215. * model 1.1.1: linear regression of as04,
  216. * respondents took arts courses outside of school ;
  217.  
  218. xi: regress as04
  219.         i.sppayear i.race sex dadgrade i.cohort1b ;
  220.  
  221.  
  222. * model 1.1.2: logistic regression of as04dum
  223. * respondents took arts courses outside of school (dummy variable) ;
  224.  
  225. xi: logistic as04dum
  226.         i.sppayear i.race sex dadgrade i.cohort1b ;
  227.  
  228.  
  229. * model 1.1.3: linear regression of asfammus,
  230. * parents of respondents listened classical music ;
  231.  
  232. xi: regress asfammus
  233.         i.sppayear i.race sex dadgrade i.cohort1b ;
  234.  
  235.  
  236.  
  237. ! echo "cps-1-1.do complete"  ; 
  238.  
  239.  
  240. * at this point, we can assume that the procedure worked.
  241. * to save disk space, the original marXX.dta will be deleted.
  242. * (best to have them backed up on disk somewhere !!) ;
  243.  
  244. ! rm -f ../data-temp/mar*.dta  ;
  245.  
  246.  
  247. exit, STATA clear  ;
  248.  
  249. * .
  250.